#ifndef	_UTIL_CORE_H_
#define _UTIL_CORE_H_


#include <util/targetos.hpp>

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

#if (TARGET_OS == OS_WINDOWS)
	#include <util/win/osdef.h>
#elif (TARGET_OS == OS_POSIX)
	#include <util/posix/osdef.h>
#elif (TARGET_OS == OS_MAC)
	#include <util/unix/osdef.h>
#endif


#include <util/common.hpp>
#include <util/bits.hpp>

#if (TARGET_OS == OS_WINDOWS)
	#include <util/win/ossysdef.h>
#elif (TARGET_OS == OS_POSIX)
	#include <util/posix/ossysdef.h>
#elif (TARGET_OS == OS_MAC)
	#include <util/unix/ossysdef.h>
#endif





#ifdef __GNUC__
#define MODULE_API                              HRESULT    OS_VISIBILITY_DEFAULT 
#define MODULE_API_                             HRESULT    OS_VISIBILITY_DEFAULT 
#else
#define MODULE_API                              HRESULT    OS_STDCALL 
#endif
#define MD_EXPORTS                              EXTERN_C   MODULE_API

#define FAILEXIT_N(x, _h_r_) 					{if(!(x)) return _h_r_; }
#define FAILEXIT_FALSE_N(x) 					{FAILEXIT_N((x),FALSE)}
#define FAILEXIT_NULL_N(x) 						{FAILEXIT_N((x),NULL)}
#define FAILEXIT_FAIL_N(x) 						{FAILEXIT_N((x),RT_FAIL)}
#define FAILEXIT_OTHER_N(x) 					{FAILEXIT_N((x),0xFFFFFFFF)}
#define FAILEXIT_FAIL_ONE(x) 					{FAILEXIT_N((x),1)}
#define FAILEXIT_FAIL_ZERO(x) 					{FAILEXIT_N((x),0)}


#define _max(a,b)								((a)>(b)?(a):(b))
#define _min(a,b)								((a)>(b)?(b):(a))
#define bzero(p,s)								memset(p,0,s)
#define tzero(p,s) 													\
	{																\
		for(unsigned long iloop = 0; iloop < s; iloop++)			\
		{															\
			bzero(&(p[iloop]), sizeof(p[0]));						\
		}															\
	}																\

#define retrtpv(x, _h_r_)                       { if(!(x))      return _h_r_; }
#define retrtnpv(x, _h_r_)                      { if((x))       return _h_r_; }

#define retret(x)                               { if(!(x))      return; }
#define retrtp(x, _h_r_)                        { if(0 == (x)) return _h_r_; }



#endif 
